package br.senac.sp.uniobjetos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import br.senac.sp.persistence.AbstractRelationalDBMapper;

public class CursoMapper extends AbstractRelationalDBMapper<Curso, Integer> {

    public CursoMapper(String tableName) {
        super(tableName);
    }

    @Override
    protected Curso getObjectFromRecord(Integer oid, ResultSet record)
            throws SQLException {
        Curso curso = new Curso();
        curso.setIdCurso(record.getInt("ID_CURSO"));
        curso.setDescricao(record.getString("DESCRICAO"));
        curso.setIdEspecie(record.getInt("ID_ESPECIE"));
        curso.setMaxAlunos(record.getInt("MAX_ALUNOS"));
        curso.setMinAlunos(record.getInt("MIN_ALUNOS"));
        return curso;
    }

    @Override
    protected Map<String, Object> getInfoFromObject(Curso entity) {
        Map<String, Object> info = new HashMap<String, Object>();
        info.put("DESCRICAO", entity.getDescricao());
        info.put("ID_ESPECIE", entity.getIdEspecie());
        info.put("MAX_ALUNOS", entity.getMaxAlunos());
        info.put("MIN_ALUNOS", entity.getMinAlunos());
        return info;
    }

    @Override
    protected Integer getIdFromObject(Curso entity) {
        return entity.getIdCurso();
    }

    @Override
    protected String getUniqueIdentifierArguments() {
        return "ID_CURSO";
    }

}
